package com.groupsix.service.impl;

import com.groupsix.entity.Admin;
import com.groupsix.mapper.AdminMapper;
import com.groupsix.utils.PageInfo;
import com.groupsix.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 管理员业务逻辑接口实现类
 * @date 2021/10/15 20:58
 */
@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    /**
     * 登录
     * @param admin
     * @return
     */
    @Override
    public Admin findAdmin(Admin admin) {
        Admin mapperAdmin = adminMapper.findAdmin(admin);
        return mapperAdmin;
    }

    @Override
    public List<Admin> getAll() {
        return adminMapper.getAll();
    }

    @Override
    public PageInfo findPageInfo(String aUsername, String aDescribe, Integer aId, Integer pageIndex, Integer pageSize) {
        PageInfo pi = new PageInfo();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = adminMapper.totalCount(aUsername,aDescribe,aId);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示管理员信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Admin> adminList =	adminMapper.getAdminList(aUsername,aDescribe,aId,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(adminList);
        }
        return pi;
    }

    @Override
    public int addAdmin(Admin admin) {
        return adminMapper.addAdmin(admin);
    }

    @Override
    public int deleteAdmin(Integer aid) {
        return adminMapper.deleteAdmin(aid);
    }

    @Override
    public int updateAdmin(Admin admin) {
        return adminMapper.updateAdmin(admin);
    }

    @Override
    public Admin findAdminById(Integer aid) {
        return adminMapper.findAdminById(aid);
    }
}
